{extend name="iframe" /}
{block name="css"}
<style type="text/css">
    .editForm{
        margin-top: 20px;
    }
    .submit_btn{
        display: none;
    }
    @media (min-width: 768px){
        .bootstrap-switch{
            margin-top: 7px;
        }
    }
</style>
{/block}

{block name="content"}
<div class="container-fluid content-wrapper-box">
    <div class="content-wrapper">
        <form class="form-horizontal editForm" action="" method="post" enctype="multipart/form-data">
            <div class="form-group">
                <label class="control-label col-xs-2">
                    商家名称&nbsp;
                </label>
                <div class="col-xs-8">
                    <p class="form-control-static">{$merchant.name}</p>
                </div>
            </div>

            <div class="form-group">
                <label class="control-label col-xs-2">
                    <em class="must_fill">*</em>服务项目&nbsp;
                </label>
                <div class="col-xs-8" style="padding-top: 7px;">
                    {foreach name="items" item="item"}
                    <label style="text-align: right;margin-left: 15px;">
                        <input type="checkbox" class="chk_role" value="{$item.id}" name="item_ids[]" {php}if( !empty($item['mch_id']) )echo 'checked="true"';{/php} >
                        {$item.service_name}
                    </label>
                    {/foreach}
                </div>
            </div>

            <input class="btn btn-primary submit_btn" onclick="submitFrom()" type="submit">
            <input class="btn btn-default reset_btn" type="hidden" onclick="resetForm()">
        </form>
    </div>
</div>
{/block}

{block name="script"}
<script type="text/javascript">
    $(function () {


        $.validator.setDefaults({
            errorPlacement: function (error, element) {
                if (element.is(":radio") || element.is(":checkbox")) {
                    error.appendTo(element.parent().parent());
                } else {
                    error.appendTo(element.parent());
                }
            }
        });

        //roles角色选择事件
        $('input.chk_role').on('click', function () {
            var $obj = $(this);
            if($obj.val()==4 /*客服角色*/){
                if( $obj.is(':checked') )
                    $('#div_leader').removeClass('hide');
                else{
                    $('#div_leader').addClass('hide');
                    $('#leader').val('0');
                }
            }
        });

    });


    //提交表单
    function submitFrom() {
        var  frameIndex= parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        //表单验证
        $(".editForm").validate({
            keydown:true,
            submitHandler: function(form) {
                $(form).ajaxSubmit({
                    dataType:'json',
                    success:function (response) {
                        if(response.code === 0){
                            parent.toastr.success(response.msg);
                            parent.layer.close(frameIndex);
                        }else{
                            parent.toastr.error(response.msg);
                        }
                        //刷新数据表格
                        parent.searchForm();
                    }
                });
            }
        })
    }
</script>
{/block}
